package com.example.mybatisplusdemo.web.controller;

import com.example.mybatisplusdemo.model.domain.ItineraryRequest;
import com.example.mybatisplusdemo.service.AdvancedFlightSearchService;
import com.example.mybatisplusdemo.common.JsonResponse;
import lombok.Data;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Data
@RestController
@RequestMapping("/api/advanced/flights")
public class AdvancedFlightSearchController {

    private final AdvancedFlightSearchService advancedSearchService;

    @PostMapping("/search")
    public JsonResponse<Object> advancedSearch(@RequestBody ItineraryRequest request) {
        try {
            return JsonResponse.success(
                    advancedSearchService.searchWithAdvancedFilters(request),
                    "高级搜索成功");
        } catch (Exception e) {
            return JsonResponse.failure("高级搜索失败: " + e.getMessage())
                    .setCode(500)
                    .setException(e);
        }
    }
}